<?php
/**
 * 微信支付
 *
 * @date    2018-07-26 10:01:35
 * @version $Id$
 */

namespace App\Commons\Services\Payment;

use App\Commons\Services\Payment\PayAdapter;
use Symfony\Component\HttpFoundation\Response;

class AlipayAdapter extends PayAdapter
{
    public function __construct()
    {
        parent::__construct('alipay');
    }

    public function scan(string $out_trade_no, string $subject, float $total_amount, array $options = [])
    {
        $result = parent::pay('scan', $out_trade_no, $subject, $total_amount);

        if ($result instanceof Response) {
            return $result;
        } else {
            return array_except($result, ['code', 'msg']);
        }
    }

    /**
     *    "gmt_create" => "2018-08-08 13:47:50"
    "charset" => "GBK"
    "seller_email" => "tangyuan@ishuidi.com.cn"
    "subject" => "春季学期"
    "buyer_id" => "2088xxxxx855"
    "invoice_amount" => "0.01"
    "notify_id" => "debedeccd306dc9565a8e48795b4494mk9"
    "fund_bill_list" => "[{"amount":"0.01","fundChannel":"PCREDIT"}]"
    "notify_type" => "trade_status_sync"
    "trade_status" => "TRADE_SUCCESS"
    "receipt_amount" => "0.01"
    "app_id" => "2018052860303181"
    "buyer_pay_amount" => "0.01"
    "sign_type" => "RSA2"
    "seller_id" => "2088131380647742"
    "gmt_payment" => "2018-08-08 13:47:54"
    "notify_time" => "2018-08-08 13:47:54"
    "version" => "1.0"
    "out_trade_no" => "AL-c85dd180445bc933321621d9e4e7e"
    "total_amount" => "0.01"
    "trade_no" => "2018080821001004850542304932"
    "auth_app_id" => "2018052860303181"
    "buyer_logon_id" => "zea***@163.com"
    "point_amount" => "0.00"
     * @return [type] [description]
     */
    public function verify()
    {
        $data = parent::verify();
        throw_on($data->trade_status !== 'TRADE_SUCCESS', '支付宝回调：订单支付失败');
        return $data;
    }
}
